<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OptionsPricing: SecondOrderStatic1D.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OptionsPricing
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_ecbb14687e1bcdda1258b79279264b64.html">models</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">SecondOrderStatic1D.py</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">#!/usr/bin/python</span>
<a name="l00002"></a>00002 <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="comment"># Copyright (c) 2011</span>
<a name="l00005"></a>00005 <span class="comment">#</span>
<a name="l00006"></a>00006 <span class="comment"># Permission is hereby granted, free of charge, to any person obtaining a</span>
<a name="l00007"></a>00007 <span class="comment"># copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<a name="l00008"></a>00008 <span class="comment"># to deal in the Software without restriction, including without limitation</span>
<a name="l00009"></a>00009 <span class="comment"># the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<a name="l00010"></a>00010 <span class="comment"># and/or sell copies of the Software, and to permit persons to whom the</span>
<a name="l00011"></a>00011 <span class="comment"># Software is furnished to do so, subject to the following conditions:</span>
<a name="l00012"></a>00012 <span class="comment">#</span>
<a name="l00013"></a>00013 <span class="comment"># The above copyright notice and this permission notice shall be included in</span>
<a name="l00014"></a>00014 <span class="comment"># all copies or substantial portions of the Software.</span>
<a name="l00015"></a>00015 <span class="comment">#</span>
<a name="l00016"></a>00016 <span class="comment"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00017"></a>00017 <span class="comment"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00018"></a>00018 <span class="comment"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00019"></a>00019 <span class="comment"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00020"></a>00020 <span class="comment"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00021"></a>00021 <span class="comment"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<a name="l00022"></a>00022 <span class="comment"># SOFTWARE.</span>
<a name="l00023"></a>00023 <span class="comment">#</span>
<a name="l00024"></a>00024 <span class="comment"># Author: Jesus Carrero &lt;j.o.carrero@gmail.com&gt;</span>
<a name="l00025"></a>00025 <span class="comment"># Mountain View, CA</span>
<a name="l00026"></a>00026 <span class="comment">#</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="stringliteral">&quot;&quot;&quot; convection diffusion reaction solver in 1D, finite element. &quot;&quot;&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="keyword">from</span> scipy <span class="keyword">import</span> asarray, zeros
<a name="l00031"></a>00031 <span class="keyword">from</span> scipy.sparse.construct <span class="keyword">import</span> spdiags
<a name="l00032"></a>00032 <span class="keyword">from</span> scipy.sparse.linalg <span class="keyword">import</span> spsolve <span class="keyword">as</span> spsolve
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">from</span> utils.Grid <span class="keyword">import</span> Grid1D
<a name="l00035"></a>00035 <span class="keyword">from</span> utils.ProjOperators <span class="keyword">import</span> oned_inner
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="keyword">from</span> AssembleStiffnesMassMatrices <span class="keyword">import</span> AssembleStiffnesMassMatrices
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 
<a name="l00040"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html">00040</a> <span class="keyword">class </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html">SecondOrderStatic1D</a>(object):
<a name="l00041"></a>00041 
<a name="l00042"></a>00042     <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00043"></a>00043 <span class="stringliteral">    solve the boundary value problem:</span>
<a name="l00044"></a>00044 <span class="stringliteral"></span>
<a name="l00045"></a>00045 <span class="stringliteral">    a*Uxx+b*Ux+cU = f</span>
<a name="l00046"></a>00046 <span class="stringliteral">    U[xleft] = uxleft</span>
<a name="l00047"></a>00047 <span class="stringliteral">    U[xright] = uxright</span>
<a name="l00048"></a>00048 <span class="stringliteral"></span>
<a name="l00049"></a>00049 <span class="stringliteral">  &quot;&quot;&quot;</span>
<a name="l00050"></a>00050 
<a name="l00051"></a>00051     __slots__ = [
<a name="l00052"></a>00052         <span class="stringliteral">&#39;m_ass_stiff&#39;</span>,
<a name="l00053"></a>00053         <span class="stringliteral">&#39;m_basis&#39;</span>,
<a name="l00054"></a>00054         <span class="stringliteral">&#39;m_mesh&#39;</span>,
<a name="l00055"></a>00055         <span class="stringliteral">&#39;m_left_bd&#39;</span>,
<a name="l00056"></a>00056         <span class="stringliteral">&#39;m_load&#39;</span>,
<a name="l00057"></a>00057         <span class="stringliteral">&#39;m_mass_diag&#39;</span>,
<a name="l00058"></a>00058         <span class="stringliteral">&#39;m_quads&#39;</span>,
<a name="l00059"></a>00059         <span class="stringliteral">&#39;m_right_bd&#39;</span>,
<a name="l00060"></a>00060         <span class="stringliteral">&#39;m_stiff_diag&#39;</span>,
<a name="l00061"></a>00061         <span class="stringliteral">&#39;m_ul&#39;</span>,
<a name="l00062"></a>00062         <span class="stringliteral">&#39;m_ur&#39;</span>,
<a name="l00063"></a>00063         ]
<a name="l00064"></a>00064 
<a name="l00065"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ab7016aa8f5feb412269b618d9bf93378">00065</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ab7016aa8f5feb412269b618d9bf93378">__init__</a>(self, nsegs, xleft, xright):
<a name="l00066"></a>00066         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00067"></a>00067 <span class="stringliteral">      m_stiff_diag ~ stiffnes as sparse diag matrix</span>
<a name="l00068"></a>00068 <span class="stringliteral">      m_basis ~ finite element space</span>
<a name="l00069"></a>00069 <span class="stringliteral">      m_mesh ~ mesh structure</span>
<a name="l00070"></a>00070 <span class="stringliteral">      m_left_bd ~ Boundary term left hand side</span>
<a name="l00071"></a>00071 <span class="stringliteral">      m_load ~ force term f(x, t)</span>
<a name="l00072"></a>00072 <span class="stringliteral">      m_mass_diag ~ mass as sparse diag matrix</span>
<a name="l00073"></a>00073 <span class="stringliteral">      m_quads ~ quadrature formulas</span>
<a name="l00074"></a>00074 <span class="stringliteral">      m_right_bd ~ Boundary term right hand side</span>
<a name="l00075"></a>00075 <span class="stringliteral">      m_stiff_diag ~ stiff matrix in diagonal-vector format</span>
<a name="l00076"></a>00076 <span class="stringliteral">      m_ul ~ left boundary condition (real number).</span>
<a name="l00077"></a>00077 <span class="stringliteral">      m_ur ~ right boundary condition (real number).</span>
<a name="l00078"></a>00078 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00079"></a>00079 
<a name="l00080"></a>00080         (self.m_basis, self.m_quads) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00081"></a>00081         (self.m_left_bd, self.m_right_bd) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00082"></a>00082         (self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#acae28f112c4c67a6eb681fac389c8c16">m_mass_diag</a>, self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ae0409ca14faf4b091c9cac0aa14bc621">m_stiff_diag</a>) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00083"></a>00083         (self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0e8318a53c7af1e50ca7fee14b797845">m_load</a>, self.m_ul, self.m_ur) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0d51c421d0f4ccfa30c01ce03c43cc6b">m_mesh</a> = Grid1D(nsegs, xleft, xright)
<a name="l00086"></a>00086         self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#af955a18189feab11b3f31a176bfca92e">m_ass_stiff</a> = AssembleStiffnesMassMatrices(self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0d51c421d0f4ccfa30c01ce03c43cc6b">m_mesh</a>)
<a name="l00087"></a>00087 
<a name="l00088"></a>00088     <span class="keyword">def </span>_mass_matrix(self):
<a name="l00089"></a>00089         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00090"></a>00090 <span class="stringliteral">       In finite elements the grid does not have to be uniform</span>
<a name="l00091"></a>00091 <span class="stringliteral">       That&#39;s why we have to use loops to assemble the matrices.</span>
<a name="l00092"></a>00092 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00093"></a>00093 
<a name="l00094"></a>00094         self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#acae28f112c4c67a6eb681fac389c8c16">m_mass_diag</a> = self.m_ass_stiff.get_mass_mat()
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a43eea604ac0be871226732f3991db3c5">00096</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a43eea604ac0be871226732f3991db3c5">get_bd_conditions</a>(self):
<a name="l00097"></a>00097         <span class="stringliteral">&quot;&quot;&quot; dirichlet bc &quot;&quot;&quot;</span>
<a name="l00098"></a>00098 
<a name="l00099"></a>00099         <span class="keywordflow">return</span> (self.m_ul, self.m_ur)
<a name="l00100"></a>00100 
<a name="l00101"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a6fe71c5e639ca5b4a784dd8fd92e4ac9">00101</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a6fe71c5e639ca5b4a784dd8fd92e4ac9">get_mesh</a>(self):
<a name="l00102"></a>00102         <span class="stringliteral">&quot;&quot;&quot; get solver&#39;s space grid.&quot;&quot;&quot;</span>
<a name="l00103"></a>00103 
<a name="l00104"></a>00104         <span class="keywordflow">return</span> self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0d51c421d0f4ccfa30c01ce03c43cc6b">m_mesh</a>
<a name="l00105"></a>00105 
<a name="l00106"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#aedc98ffb863eea5c656f6cc126ea10d3">00106</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#aedc98ffb863eea5c656f6cc126ea10d3">get_load_terms</a>(self):
<a name="l00107"></a>00107         <span class="stringliteral">&quot;&quot;&quot; return load pde&#39;s load term. &quot;&quot;&quot;</span>
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         <span class="keywordflow">return</span> oned_inner(self.m_basis, self.m_quads, self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0d51c421d0f4ccfa30c01ce03c43cc6b">m_mesh</a>,
<a name="l00110"></a>00110                           self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0e8318a53c7af1e50ca7fee14b797845">m_load</a>)
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#aa98baf79aca585df0fa14539c4f27ccf">00112</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#aa98baf79aca585df0fa14539c4f27ccf">get_mass_dformat</a>(self):
<a name="l00113"></a>00113         <span class="stringliteral">&quot;&quot;&quot; get mass matrix in diag format.&quot;&quot;&quot;</span>
<a name="l00114"></a>00114 
<a name="l00115"></a>00115         self.m_ass_stiff.discretize()
<a name="l00116"></a>00116         <span class="keywordflow">return</span> self.m_ass_stiff.get_mass_mat()
<a name="l00117"></a>00117 
<a name="l00118"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a3be57832617a25dbd2dbf96c96a2f680">00118</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a3be57832617a25dbd2dbf96c96a2f680">get_pdecos</a>(self):
<a name="l00119"></a>00119         <span class="stringliteral">&quot;&quot;&quot; Coeffients used to assemble the Matrices. &quot;&quot;&quot;</span>
<a name="l00120"></a>00120 
<a name="l00121"></a>00121         <span class="keywordflow">return</span> self.m_ass_stiff.get_pdecos()
<a name="l00122"></a>00122 
<a name="l00123"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a23465cedc1b4c2b3654161d04270852e">00123</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a23465cedc1b4c2b3654161d04270852e">get_quads</a>(self):
<a name="l00124"></a>00124         <span class="stringliteral">&quot;&quot;&quot; get quadrature formulas. &quot;&quot;&quot;</span>
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="keywordflow">return</span> self.m_quads
<a name="l00127"></a>00127 
<a name="l00128"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#af9713c7292ce90741fb06fa7aefa295b">00128</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#af9713c7292ce90741fb06fa7aefa295b">get_sfunc</a>(self):
<a name="l00129"></a>00129         <span class="stringliteral">&quot;&quot;&quot; set shape functions.&quot;&quot;&quot;</span>
<a name="l00130"></a>00130 
<a name="l00131"></a>00131         <span class="keywordflow">return</span> self.m_basis
<a name="l00132"></a>00132 
<a name="l00133"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a3ebb11efcf05a903adb9c1522a614dc6">00133</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a3ebb11efcf05a903adb9c1522a614dc6">get_stiff_dformat</a>(self):
<a name="l00134"></a>00134         <span class="stringliteral">&quot;&quot;&quot; get stiffness matrix in diag format.&quot;&quot;&quot;</span>
<a name="l00135"></a>00135 
<a name="l00136"></a>00136         self.m_ass_stiff.discretize()
<a name="l00137"></a>00137         <span class="keywordflow">return</span> self.m_ass_stiff.get_stiffness()
<a name="l00138"></a>00138 
<a name="l00139"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a6049b3427673fb49faa9c79b50ad24b6">00139</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a6049b3427673fb49faa9c79b50ad24b6">set_bd_conditions</a>(self, uleft, uright):
<a name="l00140"></a>00140         <span class="stringliteral">&quot;&quot;&quot; set boundary conditions. &quot;&quot;&quot;</span>
<a name="l00141"></a>00141 
<a name="l00142"></a>00142         (self.m_ul, self.m_ur) = (uleft, uright)
<a name="l00143"></a>00143 
<a name="l00144"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#af7604e05ffc10466ec3253a11489ddb1">00144</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#af7604e05ffc10466ec3253a11489ddb1">set_cos</a>(self, diff, conv, reac, d_is_real=True,
<a name="l00145"></a>00145             c_is_real=<span class="keyword">True</span>, r_is_real=<span class="keyword">True</span>):
<a name="l00146"></a>00146         <span class="stringliteral">&quot;&quot;&quot; set pde coeffients. both real or splines. &quot;&quot;&quot;</span>
<a name="l00147"></a>00147         self.m_ass_stiff.set_cos(diff, conv, reac, d_is_real,
<a name="l00148"></a>00148                 c_is_real, r_is_real)
<a name="l00149"></a>00149 
<a name="l00150"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ada46ed260593ba766a07f967d5cdcbf3">00150</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ada46ed260593ba766a07f967d5cdcbf3">set_sfunc_and_quads</a>(self, basis, quads):
<a name="l00151"></a>00151         <span class="stringliteral">&quot;&quot;&quot; set shape functions and quad formulas. &quot;&quot;&quot;</span>
<a name="l00152"></a>00152 
<a name="l00153"></a>00153         (self.m_basis, self.m_quads) = (basis, quads)
<a name="l00154"></a>00154         self.m_ass_stiff.set_sfunc_and_quads(basis, quads)
<a name="l00155"></a>00155 
<a name="l00156"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ad4c885be763277c5d03ea62169c89cea">00156</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ad4c885be763277c5d03ea62169c89cea">set_load</a>(self, load):
<a name="l00157"></a>00157         <span class="stringliteral">&quot;&quot;&quot; set pde load. &quot;&quot;&quot;</span>
<a name="l00158"></a>00158 
<a name="l00159"></a>00159         self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a0e8318a53c7af1e50ca7fee14b797845">m_load</a> = load
<a name="l00160"></a>00160 
<a name="l00161"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a710bd434531cf412e3b2caf1251beaf9">00161</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a710bd434531cf412e3b2caf1251beaf9">solve</a>(self):
<a name="l00162"></a>00162         <span class="stringliteral">&quot;&quot;&quot; Assemble S and RHS.</span>
<a name="l00163"></a>00163 <span class="stringliteral">            Only Dirichlet boundary condition is implemented.</span>
<a name="l00164"></a>00164 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00165"></a>00165 
<a name="l00166"></a>00166         self.m_ass_stiff.discretize()
<a name="l00167"></a>00167         self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ae0409ca14faf4b091c9cac0aa14bc621">m_stiff_diag</a> = self.m_ass_stiff.get_stiffness()
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         stiff_diag = self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ae0409ca14faf4b091c9cac0aa14bc621">m_stiff_diag</a>
<a name="l00170"></a>00170         data = [list(stiff_diag[1:-1, 0].flatten()), list(stiff_diag[1:
<a name="l00171"></a>00171                 -1, 1].flatten()), list(stiff_diag[1:-1, 2].flatten())]
<a name="l00172"></a>00172         diags = [0, 1, -1]
<a name="l00173"></a>00173 
<a name="l00174"></a>00174         rhs = self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#aedc98ffb863eea5c656f6cc126ea10d3">get_load_terms</a>()
<a name="l00175"></a>00175         <span class="keywordflow">if</span> 3 == self.m_basis.dof():
<a name="l00176"></a>00176             data.append(list(stiff_diag[1:-1, 3].flatten()))
<a name="l00177"></a>00177             data.append(list(stiff_diag[1:-1, 4].flatten()))
<a name="l00178"></a>00178             diags.append(2)
<a name="l00179"></a>00179             diags.append(-2)
<a name="l00180"></a>00180             rhs[2] -= self.m_ul * stiff_diag[0, 4]
<a name="l00181"></a>00181             rhs[-3] -= self.m_ur * stiff_diag[-1, 3]
<a name="l00182"></a>00182 
<a name="l00183"></a>00183         rhs[1] -= self.m_ul * stiff_diag[0, 2]
<a name="l00184"></a>00184         rhs[-2] -= self.m_ur * stiff_diag[-1, 1]
<a name="l00185"></a>00185 
<a name="l00186"></a>00186         load = rhs[1:-1]
<a name="l00187"></a>00187         gl_system = spdiags(asarray(data), asarray(diags), load.size,
<a name="l00188"></a>00188                             load.size).tocsc()
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         <span class="comment"># Global solution.</span>
<a name="l00191"></a>00191 
<a name="l00192"></a>00192         solu = zeros(rhs.shape)
<a name="l00193"></a>00193         (solu[0], solu[-1]) = (self.m_ul, self.m_ur)
<a name="l00194"></a>00194         solu[1:-1] = spsolve(gl_system, load).reshape((load.size, 1))
<a name="l00195"></a>00195         <span class="keywordflow">return</span> solu
<a name="l00196"></a>00196 
<a name="l00197"></a>00197 
<a name="l00198"></a><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a24ab0e3292ce66e4d6000671c99483cd">00198</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#a24ab0e3292ce66e4d6000671c99483cd">space_discretize</a>(self):
<a name="l00199"></a>00199         <span class="stringliteral">&quot;&quot;&quot; discretize in space &quot;&quot;&quot;</span>
<a name="l00200"></a>00200 
<a name="l00201"></a>00201         self.m_ass_stiff.discretize()
<a name="l00202"></a>00202         self.<a class="code" href="classmodels_1_1SecondOrderStatic1D_1_1SecondOrderStatic1D.html#ae0409ca14faf4b091c9cac0aa14bc621">m_stiff_diag</a> = self.m_ass_stiff.get_stiffness()
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Dec 22 2011 05:17:53 for OptionsPricing by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
